package jp.co.hcs.attendancemanagement.data.dao.impl;

import java.sql.SQLException;
import java.util.List;

import jp.co.hcs.attendancemanagement.data.dao.WorkingTimeActualDAO;
import jp.co.hcs.attendancemanagement.data.entity.WorkingTimeActual;
import jp.co.hcs.attendancemanagement.data.entity.ex.WorkingTimeActualExample;
import jp.co.hcs.attendancemanagement.data.entity.ex.WorkingTimeActualExample.Criteria;
import jp.co.hcs.attendancemanagement.util.StringUtil;

public class WorkingTimeActualDAOImpl extends BaseDAOImpl implements WorkingTimeActualDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public WorkingTimeActualDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int countWorkingTimeActualByExample(WorkingTimeActualExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("tb5_nichiji_jisseki.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteWorkingTimeActualByExample(WorkingTimeActualExample example) throws SQLException {
        int rows = sqlMapClient.delete("tb5_nichiji_jisseki.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteWorkingTimeActualByPrimaryKey(String employeeId, String actualWorkingDay, String actualWorkingYearMonth) throws SQLException {
        WorkingTimeActual key = new WorkingTimeActual();
        key.setEmployeeId(employeeId);
        key.setActualWorkingDay(actualWorkingDay);
        key.setActualWorkingYearMonth(actualWorkingYearMonth);
        int rows = sqlMapClient.delete("tb5_nichiji_jisseki.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertWorkingTimeActual(WorkingTimeActual record) throws SQLException {
        sqlMapClient.insert("tb5_nichiji_jisseki.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertWorkingTimeActualSelective(WorkingTimeActual record) throws SQLException {
        sqlMapClient.insert("tb5_nichiji_jisseki.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    @SuppressWarnings("unchecked")
    public List<WorkingTimeActual> selectWorkingTimeActualByExample(WorkingTimeActualExample example) throws SQLException {
        List<WorkingTimeActual> list = sqlMapClient.queryForList("tb5_nichiji_jisseki.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public WorkingTimeActual selectWorkingTimeActualByPrimaryKey(String employeeId, String actualWorkingDay, String actualWorkingYearMonth) throws SQLException {
        WorkingTimeActual key = new WorkingTimeActual();
        key.setEmployeeId(employeeId);
        key.setActualWorkingDay(actualWorkingDay);
        key.setActualWorkingYearMonth(actualWorkingYearMonth);
        WorkingTimeActual record = (WorkingTimeActual) sqlMapClient.queryForObject("tb5_nichiji_jisseki.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateWorkingTimeActualByExampleSelective(WorkingTimeActual record, WorkingTimeActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_nichiji_jisseki.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateWorkingTimeActualByExample(WorkingTimeActual record, WorkingTimeActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_nichiji_jisseki.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateWorkingTimeActualByPrimaryKeySelective(WorkingTimeActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_nichiji_jisseki.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateWorkingTimeActualByPrimaryKey(WorkingTimeActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_nichiji_jisseki.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table tb5_nichiji_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    private static class UpdateByExampleParms extends WorkingTimeActualExample {
        private Object record;

        public UpdateByExampleParms(Object record, WorkingTimeActualExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
    
    public String getDailyWorkingActualResultStatus(String employerCode, String selectPeriod, String day) throws SQLException
	{
    	String dailyWorkingActualResultStatus = "";
		WorkingTimeActualExample example = new WorkingTimeActualExample();
		Criteria criteria =  example.createCriteria();
		criteria.andEmployeeIdEqualTo(employerCode);
		criteria.andActualWorkingYearMonthEqualTo(selectPeriod);
		criteria.andActualWorkingDayEqualTo(day);
		List<WorkingTimeActual> workingTimeActualList = selectWorkingTimeActualByExample(example);
		
		for(WorkingTimeActual w:workingTimeActualList)
		{
			dailyWorkingActualResultStatus = w.getApprovalStatus();
		}
		return dailyWorkingActualResultStatus;
	}

	@Override
	public String getOvertimeWorkingPerMonth(String employeeId, String yearMonth)
			throws SQLException {
		WorkingTimeActual key = new WorkingTimeActual();
        key.setEmployeeId(employeeId);
        key.setActualWorkingYearMonth(yearMonth);
        String total = (String) sqlMapClient.queryForObject("tb5_nichiji_jisseki.getOvertimeWorkingPerMonth", key);
		return StringUtil.convertStringTotalTimetoDisplayFormat(total);
	}
	
}